################################################################################
## Group Identities and Parliamentary Debates: Replication package
## Fiva, Nedregård and Øien (2025)

# Description:

## Code to make Fig 3b: "Most divergent words across blocs"

################################################################################

library(xtable)
library(data.table)


# Directories (wd is set by master.R)

data.dir <-  "../data/3_model_output"
tab.dir  <- "../results/tables"



#########
# Gender
# Reading top50 divergent words

t <- fread(paste(data.dir, "di_trans_words_top50_gender.csv", sep = "/"))


t.gender <- t[rank < 16, .(rank, words_female_translated, words_male = words_0_translated)]


#########
# Age
# Reading top50 divergent words

t <- fread(paste(data.dir, "di_trans_words_top50_age.csv", sep = "/"))


t.age <- t[1:15, .(words_old_translated, words_young = words_0_translated)]

t <- cbind(t.gender, t.age)

t <- xtable(t, method = c("compact"), booktabs = T)



print.xtable(t, only.contents = T, comment = F, hline.after = NULL, 
             include.colnames = F, include.rownames = F, 
             file = paste(tab.dir, "tab1a.tex", sep = "/"))



#########
# Urbanicity
# Reading top50 divergent words

t <- fread(paste(data.dir, "di_trans_words_top50_urban.csv", sep = "/"))


t_urban <- t[1:15, .(rank, words_urban_translated, words_rural = words_0_translated)]




#########
# Background
# Reading top50 divergent words

t <- fread(paste(data.dir, "di_trans_words_top50_background.csv", sep = "/")) 


t_background <- t[1:15, .(words_white_translated, words_blue = words_0_translated)]



t <- cbind(t_urban, t_background)

t <- xtable(t, method = c("compact"), booktabs = T)



print.xtable(t, only.contents = T, comment = F, hline.after = NULL, 
             include.colnames = F, include.rownames = F, 
             file = paste(tab.dir, "tab1b.tex", sep = "/"))

